Date: Sat, 10 Jul 2021 16:54:17 +0300 From: Konstantin Belousov <kostikbel@gmail.com> To: Vitaliy Gusev <gusev.vitaliy@gmail.com> Cc: freebsd-hackers@freebsd.org, gljennjohn@gmail.com, Mark Johnston <markj@freebsd.org>, Peter Grehan <grehan@freebsd.org> Subject: Re: madvise(MADV_FREE) doesn't work in some cases? Message-ID: <YOmmicfMXPHQ4eY2@kib.kiev.ua> In-Reply-To: <A3E8A5E9-5912-4358-B384-1FC5847DCBE6@gmail.com> References: <D5749BDF-36B5-4AE9-A75F-2A702DF71F8C@gmail.com> <20210703065420.6dbafb5f@ernst.home> <D542E8C1-4E97-48E8-8748-BBA19B2216EC@gmail.com> <2390FA9B-319E-45D4-BEA7-10878E43AD4B@gmail.com> <YONVgjgqREDAucok@kib.kiev.ua> <2A7A1E60-766D-427B-8288-E92B4090022E@gmail.com> <A3E8A5E9-5912-4358-B384-1FC5847DCBE6@gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jul 06, 2021 at 01:21:17AM +0300, Vitaliy Gusev wrote: > Comments are below, > > > commit 0392eb3c93b7dacc31dbdf8ec2fc40fa5ba67c62 > > Author: Konstantin Belousov <kib@FreeBSD.org <mailto:kib@FreeBSD.org>> > > Date: Mon Jul 5 21:53:22 2021 +0300 > > > > madvise(MADV_FREE): try harder to handle shadow chain > > > > In particular, collapse top object and see if there is no backing object > > after, which means that we would not revert to older content if drop the > > top object. > > > > diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c > > index 1ac4ccf72f11..80abac223f29 100644 > > --- a/sys/vm/vm_map.c > > +++ b/sys/vm/vm_map.c > > @@ -3033,6 +3033,7 @@ vm_map_madvise( > > entry = vm_map_entry_succ(entry); > > for (; entry->start < end; > > entry = vm_map_entry_succ(entry)) { > > + vm_object_t obj; > > vm_offset_t useEnd, useStart; > > > > if ((entry->eflags & MAP_ENTRY_IS_SUB_MAP) != 0) > > @@ -3046,9 +3047,16 @@ vm_map_madvise( > > * backing object can change. > > */ > > if (behav == MADV_FREE && > > - entry->object.vm_object != NULL && > > - entry->object.vm_object->backing_object != NULL) > > - continue; > > + (obj = entry->object.vm_object) != NULL && > > + obj->backing_object != NULL) { > > + VM_OBJECT_WLOCK(obj); > > + if ((obj->flags & OBJ_DEAD) != 0) > > + continue; > > Here is object is left locked, however I didn’t met this condition. Right. > > > + vm_object_collapse(obj); > > + VM_OBJECT_WUNLOCK(obj); > > + if (obj->backing_object != NULL) > > + continue; > > After testing it looks that backing_object is not null here, memory is not freed and mmapfork test program is still killed. Any ideas? > I finally looked at this thing again. You do madvise(PAGE_SIZE). With my patch (updated version below) issue madvise() for the whole region once. commit b183ec9e985961bd0b450d9e7bdbbcde751c830b Author: Konstantin Belousov <kib@FreeBSD.org> Date: Mon Jul 5 21:53:22 2021 +0300 madvise(MADV_FREE): try harder to handle shadow chain In particular, collapse top object and see if there is no backing object after, which means that we would not revert to older content if drop the top object. diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 1ac4ccf72f11..188b37560e0e 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -3033,6 +3033,7 @@ vm_map_madvise( entry = vm_map_entry_succ(entry); for (; entry->start < end; entry = vm_map_entry_succ(entry)) { + vm_object_t obj; vm_offset_t useEnd, useStart; if ((entry->eflags & MAP_ENTRY_IS_SUB_MAP) != 0) @@ -3046,9 +3047,18 @@ vm_map_madvise( * backing object can change. */ if (behav == MADV_FREE && - entry->object.vm_object != NULL && - entry->object.vm_object->backing_object != NULL) - continue; + (obj = entry->object.vm_object) != NULL && + obj->backing_object != NULL) { + VM_OBJECT_WLOCK(obj); + if ((obj->flags & OBJ_DEAD) != 0) { + VM_OBJECT_WUNLOCK(obj); + continue; + } + vm_object_collapse(obj); + VM_OBJECT_WUNLOCK(obj); + if (obj->backing_object != NULL) + continue; + } pstart = OFF_TO_IDX(entry->offset); pend = pstart + atop(entry->end - entry->start);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?YOmmicfMXPHQ4eY2>