Author: Armin Rigo <ar...@tunes.org> Branch: use-madv-free Changeset: r85686:83477b04d5ed Date: 2016-07-14 11:11 +0200 http://bitbucket.org/pypy/pypy/changeset/83477b04d5ed/
Log: Test and fix diff --git a/rpython/rtyper/lltypesystem/llarena.py b/rpython/rtyper/lltypesystem/llarena.py --- a/rpython/rtyper/lltypesystem/llarena.py +++ b/rpython/rtyper/lltypesystem/llarena.py @@ -445,11 +445,11 @@ pagesize = posixpagesize.get() baseaddr = rffi.cast(lltype.Signed, baseaddr) - aligned_addr = (baseaddr + pagesize - 1) & (pagesize - 1) + aligned_addr = (baseaddr + pagesize - 1) & ~(pagesize - 1) size -= (aligned_addr - baseaddr) if size >= pagesize: rmmap.madvise_free(rffi.cast(rmmap.PTR, aligned_addr), - size & (pagesize - 1)) + size & ~(pagesize - 1)) else: # XXX any better implementation on Windows? diff --git a/rpython/rtyper/lltypesystem/test/test_llarena.py b/rpython/rtyper/lltypesystem/test/test_llarena.py --- a/rpython/rtyper/lltypesystem/test/test_llarena.py +++ b/rpython/rtyper/lltypesystem/test/test_llarena.py @@ -1,6 +1,6 @@ -import py +import py, os -from rpython.rtyper.lltypesystem import lltype, llmemory +from rpython.rtyper.lltypesystem import lltype, llmemory, rffi, llarena from rpython.rtyper.lltypesystem.llarena import (arena_malloc, arena_reset, arena_reserve, arena_free, round_up_for_allocation, ArenaError, arena_new_view, arena_shrink_obj, arena_protect, has_protect) @@ -299,6 +299,29 @@ p.x = 125 assert p.x == 125 +def test_madvise_arena_free(): + from rpython.rlib import rmmap + + if os.name != 'posix': + py.test.skip("posix only") + pagesize = llarena.posixpagesize.get() + prev = rmmap.madvise_free + try: + seen = [] + def my_madvise_free(addr, size): + assert lltype.typeOf(addr) == rmmap.PTR + seen.append((addr, size)) + rmmap.madvise_free = my_madvise_free + llarena.madvise_arena_free( + rffi.cast(llmemory.Address, 123 * pagesize + 1), + pagesize * 7 - 2) + finally: + rmmap.madvise_free = prev + assert len(seen) == 1 + addr, size = seen[0] + assert rffi.cast(lltype.Signed, addr) == 124 * pagesize + assert size == pagesize * 5 + class TestStandalone(test_standalone.StandaloneTests): def test_compiled_arena_protect(self): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit