From: "Huang\, Ying" <ying.huang@intel.com>
To: Uladzislau Rezki <urezki@gmail.com>
Cc: huang ying <huang.ying.caritas@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>,
Hillf Danton <hdanton@sina.com>, Michal Hocko <mhocko@suse.com>,
Matthew Wilcox <willy@infradead.org>,
Oleksiy Avramchenko <oleksiy.avramchenko@sonymobile.com>,
Steven Rostedt <rostedt@goodmis.org>,
Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH 2/2] mm/vmalloc: rework the drain logic
Date: Tue, 24 Nov 2020 10:25:23 +0800 [thread overview]
Message-ID: <875z5vtrsc.fsf@yhuang-dev.intel.com> (raw)
In-Reply-To: <20201123135919.GA12236@pc636> (Uladzislau Rezki's message of "Mon, 23 Nov 2020 14:59:19 +0100")
Uladzislau Rezki <urezki@gmail.com> writes:
>> >> >> And I found the long latency avoidance logic in
>> >> >> __purge_vmap_area_lazy() appears problematic,
>> >> >>
>> >> >> if (atomic_long_read(&vmap_lazy_nr) < resched_threshold)
>> >> >> cond_resched_lock(&free_vmap_area_lock);
>> >> >>
>> >> >> Shouldn't it be something as follows?
>> >> >>
>> >> >> if (i >= BATCH && atomic_long_read(&vmap_lazy_nr) <
>> >> >> resched_threshold) {
>> >> >> cond_resched_lock(&free_vmap_area_lock);
>> >> >> i = 0;
>> >> >> } else
>> >> >> i++;
>> >> >>
>> >> >> This will accelerate the purging via batching and slow down vmalloc()
>> >> >> via holding free_vmap_area_lock. If it makes sense, can we try this?
>> >> >>
>> >> > Probably we can switch to just using "batch" methodology:
>> >> >
>> >> > <snip>
>> >> > if (!(i++ % batch_threshold))
>> >> > cond_resched_lock(&free_vmap_area_lock);
>> >> > <snip>
>> >>
>> >> That's the typical long latency avoidance method.
>> >>
>> >> > The question is, which value we should use as a batch_threshold: 100, 1000, etc.
>> >>
>> >> I think we can do some measurement to determine it?
>> >>
>> > Hmm.. looking at it one more time i do not see what batching solves.
>>
>> Without batch protection, we may release the lock and CPU anytime during
>> looping if "vmap_lazy_nr < resched_threshold". Too many vmalloc/vfree
>> may be done during that. So I think we can restrict it. Batching can
>> improve the performance of purging itself too.
>>
> In theory:
> I see your point. It is a trade-off though, to allow faster vmalloc or vfree.
> Batching will make alloc more tight, and yes, speed up the process of draining
> holding a CPU until batch is drained + introducing latency for other tasks.
>
> In practical:
> I mentioned about that, i think we need to measure the batching approach, say
> we set it to 100, providing some figures so we see some evidence from practical
> point of view. For example run test_vmalloc.sh to analyze it. If you see some
> advantages from performance point of view it would be great. Just share some
> data.
Per my understanding, this is the common practice in kernel to satisfy
both throughput and latency requirement. But it may be not important
for this specific case. I am afraid I have no time to work on this now.
Just my 2 cents. If you don't think that's a good idea, just ignore it.
>> > Anyway we need to have some threshold(what we do have), that regulates
>> > a priority between vmalloc()/vfree().
>> >
>> > What we can do more with it are:
>> >
>> > - purging should be just performed asynchronously in workqueue context.
>> > Giving the fact, that now we also do a merge of outstanding areas, the
>> > data structure(rb-tree) will not be so fragmented.
>>
>> Async works only if there are idle CPU time on other CPUs. And it may
>> punish other innocent workloads instead of the heavy vmalloc/vfree
>> users. So we should be careful about that.
>>
> Yep, scheduling latency will be as a side affect of such approach. The question
> is if it is negligible and can be considered as a risk. I do not think it would
> be a big problem.
>
> I have other issue with it though, which i can not explain so far. If i am doing
> the "purge" in the separate worker, i see that a memory leaks after heavy test
> runs.
>
>> > - lazy_max_pages() can slightly be decreased. If there are existing
>> > workloads which suffer from such long value. It would be good to get
>> > real complains and evidence.
>> >
>> >> > Apart of it and in regard to CONFIG_KASAN_VMALLOC, it seems that we are not
>> >> > allowed to drop the free_vmap_area_lock at all. Because any simultaneous
>> >> > allocations are not allowed within a drain region, so it should occur in
>> >> > disjoint regions. But i need to double check it.
>> >> >
>> >> >>
>> >> >> And, can we reduce lazy_max_pages() to control the length of the
>> >> >> purging list? It could be > 8K if the vmalloc/vfree size is small.
>> >> >>
>> >> > We can adjust it for sure. But it will influence on number of global
>> >> > TLB flushes that must be performed.
>> >>
>> >> Em... For example, if we set it to 100, then the number of the TLB
>> >> flushes can be reduced to 1% of the un-optimized implementation
>> >> already. Do you think so?
>> >>
>> > If we set lazy_max_pages() to vague value such as 100, the performance
>> > will be just destroyed.
>>
>> Sorry, my original words weren't clear enough. What I really want to
>> suggest is to control the length of the purging list instead of reduce
>> lazy_max_pages() directly. That is, we can have a "atomic_t
>> nr_purge_item" to record the length of the purging list and start
>> purging if (vmap_lazy_nr > lazy_max_pages && nr_purge_item >
>> max_purge_item). vmap_lazy_nr is to control the virtual address space,
>> nr_purge_item is to control the batching purging latency. "100" is just
>> an example, the real value should be determined according to the test
>> results.
>>
> OK. Now i see what you meant. Please note, the merging is in place, so
> the list size gets reduced.
Yes. In theory, even with merging, the length of the purging list may
become too long in some cases. And the code/algorithm changes that are
needed by controlling the length of the purging list is much less than
that are needed by merging. So I suggest to do length controlling
firstly, then merging. Again, just my 2 cents.
Best Regards,
Huang, Ying
next prev parent reply other threads:[~2020-11-24 2:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-16 22:00 [PATCH 1/2] mm/vmalloc: use free_vm_area() if an allocation fails Uladzislau Rezki (Sony)
2020-11-16 22:00 ` [PATCH 2/2] mm/vmalloc: rework the drain logic Uladzislau Rezki (Sony)
2020-11-17 2:37 ` huang ying
2020-11-17 13:04 ` Uladzislau Rezki
2020-11-18 2:44 ` huang ying
2020-11-18 16:16 ` Uladzislau Rezki
2020-11-19 1:40 ` Huang, Ying
2020-11-19 17:36 ` Uladzislau Rezki
2020-11-20 2:34 ` Huang, Ying
2020-11-23 13:59 ` Uladzislau Rezki
2020-11-24 2:25 ` Huang, Ying [this message]
2020-11-24 16:40 ` Uladzislau Rezki
2020-11-25 0:52 ` Huang, Ying
2020-11-25 20:34 ` Uladzislau Rezki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=875z5vtrsc.fsf@yhuang-dev.intel.com \
--to=ying.huang@intel.com \
--cc=akpm@linux-foundation.org \
--cc=hch@lst.de \
--cc=hdanton@sina.com \
--cc=huang.ying.caritas@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=oleksiy.avramchenko@sonymobile.com \
--cc=rostedt@goodmis.org \
--cc=urezki@gmail.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).