Date: Tue, 23 Oct 2018 14:11:36 +0000 (UTC) From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339655 - head/contrib/jemalloc/src Message-ID: <201810231411.w9NEBaIl051200@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: trasz Date: Tue Oct 23 14:11:35 2018 New Revision: 339655 URL: https://svnweb.freebsd.org/changeset/base/339655 Log: Pick f80c97e477d1b3fe7778c65d9439d673738b4131 from upstream: Rework the way jemalloc uses mmap(2) on FreeBSD. This makes it directly use MAP_EXCL and MAP_ALIGNED() instead of weird workarounds involving mapping at random places and then unmapping parts of them. Discussed with: jasone MFC after: 2 weeks Sponsored by: DARPA, AFRL Modified: head/contrib/jemalloc/src/pages.c Modified: head/contrib/jemalloc/src/pages.c ============================================================================== --- head/contrib/jemalloc/src/pages.c Tue Oct 23 13:54:54 2018 (r339654) +++ head/contrib/jemalloc/src/pages.c Tue Oct 23 14:11:35 2018 (r339655) @@ -180,6 +180,31 @@ pages_map(void *addr, size_t size, size_t alignment, b assert(alignment >= PAGE); assert(ALIGNMENT_ADDR2BASE(addr, alignment) == addr); +#if defined(__FreeBSD__) && defined(MAP_EXCL) + /* + * FreeBSD has mechanisms both to mmap at specific address without + * touching existing mappings, and to mmap with specific alignment. + */ + { + int prot = *commit ? PAGES_PROT_COMMIT : PAGES_PROT_DECOMMIT; + int flags = mmap_flags; + + if (addr != NULL) { + flags |= MAP_FIXED | MAP_EXCL; + } else { + unsigned alignment_bits = ffs_zu(alignment); + assert(alignment_bits > 1); + flags |= MAP_ALIGNED(alignment_bits - 1); + } + + void *ret = mmap(addr, size, prot, flags, -1, 0); + if (ret == MAP_FAILED) { + ret = NULL; + } + + return ret; + } +#endif /* * Ideally, there would be a way to specify alignment to mmap() (like * NetBSD has), but in the absence of such a feature, we have to work
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201810231411.w9NEBaIl051200>