From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C0FAC3F2D6 for ; Fri, 6 Mar 2020 13:13:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DDFBA208CD for ; Fri, 6 Mar 2020 13:13:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DDFBA208CD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6B0E06B0005; Fri, 6 Mar 2020 08:13:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 660A16B0006; Fri, 6 Mar 2020 08:13:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5760E6B0007; Fri, 6 Mar 2020 08:13:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0181.hostedemail.com [216.40.44.181]) by kanga.kvack.org (Postfix) with ESMTP id 40ECE6B0005 for ; Fri, 6 Mar 2020 08:13:54 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D83592C14 for ; Fri, 6 Mar 2020 13:13:53 +0000 (UTC) X-FDA: 76564979946.21.truck43_3f14cbe43960c X-HE-Tag: truck43_3f14cbe43960c X-Filterd-Recvd-Size: 4365 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Fri, 6 Mar 2020 13:13:53 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 7837FAC1E; Fri, 6 Mar 2020 13:13:51 +0000 (UTC) Subject: Re: [PATCH v7 7/7] mm/madvise: allow KSM hints for remote API To: Minchan Kim , Andrew Morton Cc: LKML , linux-mm , linux-api@vger.kernel.org, oleksandr@redhat.com, Suren Baghdasaryan , Tim Murray , Daniel Colascione , Sandeep Patil , Sonny Rao , Brian Geffon , Michal Hocko , Johannes Weiner , Shakeel Butt , John Dias , Joel Fernandes , Jann Horn , alexander.h.duyck@linux.intel.com, sj38.park@gmail.com, SeongJae Park References: <20200302193630.68771-1-minchan@kernel.org> <20200302193630.68771-8-minchan@kernel.org> From: Vlastimil Babka Message-ID: <2a66abd8-4103-f11b-06d1-07762667eee6@suse.cz> Date: Fri, 6 Mar 2020 14:13:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200302193630.68771-8-minchan@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 3/2/20 8:36 PM, Minchan Kim wrote: > From: Oleksandr Natalenko > > It all began with the fact that KSM works only on memory that is marked > by madvise(). And the only way to get around that is to either: > > * use LD_PRELOAD; or > * patch the kernel with something like UKSM or PKSM. > > (i skip ptrace can of worms here intentionally) > > To overcome this restriction, lets employ a new remote madvise API. This > can be used by some small userspace helper daemon that will do auto-KSM > job for us. > > I think of two major consumers of remote KSM hints: > > * hosts, that run containers, especially similar ones and especially in > a trusted environment, sharing the same runtime like Node.js; > > * heavy applications, that can be run in multiple instances, not > limited to opensource ones like Firefox, but also those that cannot be > modified since they are binary-only and, maybe, statically linked. > > Speaking of statistics, more numbers can be found in the very first > submission, that is related to this one [1]. For my current setup with > two Firefox instances I get 100 to 200 MiB saved for the second instance > depending on the amount of tabs. > > 1 FF instance with 15 tabs: > > $ echo "$(cat /sys/kernel/mm/ksm/pages_sharing) * 4 / 1024" | bc > 410 > > 2 FF instances, second one has 12 tabs (all the tabs are different): > > $ echo "$(cat /sys/kernel/mm/ksm/pages_sharing) * 4 / 1024" | bc > 592 > > At the very moment I do not have specific numbers for containerised > workload, but those should be comparable in case the containers share > similar/same runtime. > > [1] https://lore.kernel.org/patchwork/patch/1012142/ > > Reviewed-by: SeongJae Park > Signed-off-by: Oleksandr Natalenko > Signed-off-by: Minchan Kim This will lead to one process calling unmerge_ksm_pages() of another. There's a (signal_pending(current)) test there, should it check also the other task, analogically to task 3? Then break_ksm() is fine as it is, as ksmd also calls it, right? > --- > mm/madvise.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/mm/madvise.c b/mm/madvise.c > index e77c6c1fad34..f4fa962ee74d 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -1005,6 +1005,10 @@ process_madvise_behavior_valid(int behavior) > switch (behavior) { > case MADV_COLD: > case MADV_PAGEOUT: > +#ifdef CONFIG_KSM > + case MADV_MERGEABLE: > + case MADV_UNMERGEABLE: > +#endif > return true; > default: > return false; >