So mongodb didn't show up when guenther@ looked for mincore(2) users in
ports, because the search was done over i386 .o, but mongodb is only for
amd64.

Here's a diff to unbreak it.  There's a "feature check" function
blockCheckSupported() which now returns false, if code ends up querying
the presence of pages in memory with blockInMemory() or pagesInMemory()
the answer will also be false.  I think those defaults are consistent
with the choices made in src/mongo/db/storage/mmap_v1/record_access_tracker.cpp
See "if (!_blockSupported)".

--8<--
bool RecordAccessTracker::checkAccessedAndMark(const void* record) {
    const size_t page = reinterpret_cast<size_t>(record) >> 12;
    const size_t region = page >> 6;
    const size_t offset = page & 0x3f;

    // This is like the "L1 cache". If we're a miss then we fall through and 
check the
    // "L2 cache". If we're still a miss, then we defer to a system-specific 
system
    // call (or give up and return false if deferring to the system call is not 
enabled).
    if (PointerTable::seen(PointerTable::getData(), 
reinterpret_cast<size_t>(record))) {
        return true;
    }

    // We were a miss in the PointerTable. See if we can find 'record' in the 
Rolling table.
    if (_rollingTable[bigHash(region)].access(region, offset, false)) {
        return true;
    }

    if (!_blockSupported) {
        // This means we don't fall back to a system call. Instead we assume 
things aren't
        // in memory. This could mean that we yield too much, but this is much 
better
        // than the alternative of not yielding through a page fault.
        return false;
    }

    return ProcessInfo::blockInMemory(const_cast<void*>(record));
}
-->8--

mongodb will now print a warning on startup:
--8<--
 2019-01-12T13:56:00.082+0100 I CONTROL  [initandlisten] ** NOTE: your 
operating system version does not support the method that MongoDB
 2019-01-12T13:56:00.082+0100 I CONTROL  [initandlisten] **       uses to 
detect impending page faults.
 2019-01-12T13:56:00.082+0100 I CONTROL  [initandlisten] **       This may 
result in slower performance for certain use cases
-->8--

On a new install I had to tweak the rcscript so that the default log
file can be opened and written to.  I can commit that part separately.


ok?


Index: Makefile
===================================================================
RCS file: /cvs/ports/databases/mongodb/Makefile,v
retrieving revision 1.33
diff -u -p -r1.33 Makefile
--- Makefile    13 Dec 2018 19:53:23 -0000      1.33
+++ Makefile    12 Jan 2019 12:59:25 -0000
@@ -12,7 +12,7 @@ COMMENT =     scalable, high-performance doc
 DISTNAME =     mongodb-src-r3.2.13
 PKGNAME =      ${DISTNAME:S/src-r//}
 CATEGORIES =   databases
-REVISION =     3
+REVISION =     4
 
 HOMEPAGE =     https://www.mongodb.com/
 
Index: patches/patch-src_mongo_util_processinfo_openbsd_cpp
===================================================================
RCS file: 
/cvs/ports/databases/mongodb/patches/patch-src_mongo_util_processinfo_openbsd_cpp,v
retrieving revision 1.1
diff -u -p -r1.1 patch-src_mongo_util_processinfo_openbsd_cpp
--- patches/patch-src_mongo_util_processinfo_openbsd_cpp        8 Jun 2017 
16:16:43 -0000       1.1
+++ patches/patch-src_mongo_util_processinfo_openbsd_cpp        12 Jan 2019 
12:59:25 -0000
@@ -1,5 +1,8 @@
 $OpenBSD: patch-src_mongo_util_processinfo_openbsd_cpp,v 1.1 2017/06/08 
16:16:43 sthen Exp $
 
+- avoid use after free
+- mincore(2) has been removed
+
 Index: src/mongo/util/processinfo_openbsd.cpp
 --- src/mongo/util/processinfo_openbsd.cpp.orig
 +++ src/mongo/util/processinfo_openbsd.cpp
@@ -27,3 +30,35 @@ Index: src/mongo/util/processinfo_openbs
  }
  
  double ProcessInfo::getSystemMemoryPressurePercentage() {
+@@ -182,28 +184,14 @@ bool ProcessInfo::supported() {
+ }
+ 
+ bool ProcessInfo::blockCheckSupported() {
+-    return true;
++    return false;
+ }
+ 
+ bool ProcessInfo::blockInMemory(const void* start) {
+-    char x = 0;
+-    if (mincore((void*)alignToStartOfPage(start), getPageSize(), &x)) {
+-        log() << "mincore failed: " << errnoWithDescription() << endl;
+-        return 1;
+-    }
+-    return x & 0x1;
++    return false;
+ }
+ 
+ bool ProcessInfo::pagesInMemory(const void* start, size_t numPages, 
vector<char>* out) {
+-    out->resize(numPages);
+-    // int mincore(const void *addr, size_t len, char *vec);
+-    if (mincore((void*)alignToStartOfPage(start), numPages * getPageSize(), 
&(out->front()))) {
+-        log() << "mincore failed: " << errnoWithDescription() << endl;
+-        return false;
+-    }
+-    for (size_t i = 0; i < numPages; ++i) {
+-        (*out)[i] = 0x1;
+-    }
+-    return true;
++    return false;
+ }
+ }
Index: pkg/mongod.rc
===================================================================
RCS file: /cvs/ports/databases/mongodb/pkg/mongod.rc,v
retrieving revision 1.2
diff -u -p -r1.2 mongod.rc
--- pkg/mongod.rc       11 Jan 2018 19:27:01 -0000      1.2
+++ pkg/mongod.rc       12 Jan 2019 12:59:25 -0000
@@ -10,4 +10,8 @@ daemon_user="_mongodb"
 
 rc_reload=NO
 
+rc_pre() {
+       install -d -m 755 -o _mongodb -g _mongodb /var/log/mongodb
+}
+
 rc_cmd $1

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to