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=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 CBF2AC10DCE for ; Fri, 6 Mar 2020 13:41:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8325E2072D for ; Fri, 6 Mar 2020 13:41:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SGsjmFwT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8325E2072D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 143F06B0005; Fri, 6 Mar 2020 08:41:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CE326B0006; Fri, 6 Mar 2020 08:41:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED80F6B0007; Fri, 6 Mar 2020 08:41:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id D1D7A6B0005 for ; Fri, 6 Mar 2020 08:41:55 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7CB6E824556B for ; Fri, 6 Mar 2020 13:41:55 +0000 (UTC) X-FDA: 76565050590.24.robin14_10c134fe6ef07 X-HE-Tag: robin14_10c134fe6ef07 X-Filterd-Recvd-Size: 7447 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Fri, 6 Mar 2020 13:41:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583502114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zggKkN7hGox22JPHoDRSQGCHbKArCwY41aGutJYJw7M=; b=SGsjmFwTyFNwIYNcX6lqqHJBpQnifKHHXQYkwMrk52l9ZQKdX/hnvTQYO3jo8C+fBhyVsC eCgz0AJ4NVYIIdS076WllEGmRG6UXzCIYctgfnV2a84s1Ag+sHdw08uGz/PRVlVi5VJus8 in4Z3NYwUVzDqW2Q7ZEw5HRl5OEV6V8= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-435-G-jK_vdMPCqCCNwZrkl0dA-1; Fri, 06 Mar 2020 08:41:50 -0500 X-MC-Unique: G-jK_vdMPCqCCNwZrkl0dA-1 Received: by mail-wr1-f70.google.com with SMTP id q18so1009108wrw.5 for ; Fri, 06 Mar 2020 05:41:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=IEMTcz44qXHTvt90A4c5VFOdWnApL2YdhivNGIEppTM=; b=FAzW6YDubufQhOfZnELitq1WFJSyxZ+yyLGLrZhk6Of85FVHl1bQCWddJnY/3JS4Sk IiwrDN01ECJ9EY6MEOair6R9j1sBHZlxkAiA8jmNQ3jSSXzwuI4204+epYc1UaIqbseV 4ffAZKB9hKhclgibOqY0G2OvkgrGqkYaQeCxsusz/ckoEMD8BQNteVDyt9zgsDYCc7V5 G+kVM38K8mLzaxRS+KMBHU+4oHxML9BzdWkyMlz4fSWuZJ4HBrKjzS7q2dugqljSvEhd PWKCEGndtIqHTNwPV1M2Su2zi+YlxmfZSNQyeF86dlDbGe++bvrhry7U764kpnn/XUNB blhw== X-Gm-Message-State: ANhLgQ0ToH1zyqULKHcTs8QBXFSg4Y9I36tIO97VztZYAkplizR1ZPS2 o4lxlE2fE70pCQL4iLc0uvidpyFmfuu+SSUIOt/NAXOqw3yiEyKKz0NKe6PQTGFueDZTB0RfC11 zu3irlzBYc6o= X-Received: by 2002:a05:6000:8f:: with SMTP id m15mr3969862wrx.378.1583502107898; Fri, 06 Mar 2020 05:41:47 -0800 (PST) X-Google-Smtp-Source: ADFU+vudibnT4plTiR2nZQMFqrEAK+dvcF740xf/jWy6W7N3p01s46FIR4Rp6M3hJC+gN4drevJpkA== X-Received: by 2002:a05:6000:8f:: with SMTP id m15mr3969818wrx.378.1583502107595; Fri, 06 Mar 2020 05:41:47 -0800 (PST) Received: from localhost ([2001:470:5b39:28:1273:be38:bc73:5c36]) by smtp.gmail.com with ESMTPSA id w9sm10573301wrn.35.2020.03.06.05.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2020 05:41:46 -0800 (PST) Date: Fri, 6 Mar 2020 14:41:46 +0100 From: Oleksandr Natalenko To: Vlastimil Babka Cc: Minchan Kim , Andrew Morton , LKML , linux-mm , linux-api@vger.kernel.org, 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 Subject: Re: [PATCH v7 7/7] mm/madvise: allow KSM hints for remote API Message-ID: <20200306134146.mqiyvsdnqty7so53@butterfly.localdomain> References: <20200302193630.68771-1-minchan@kernel.org> <20200302193630.68771-8-minchan@kernel.org> <2a66abd8-4103-f11b-06d1-07762667eee6@suse.cz> MIME-Version: 1.0 In-Reply-To: <2a66abd8-4103-f11b-06d1-07762667eee6@suse.cz> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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 Fri, Mar 06, 2020 at 02:13:49PM +0100, Vlastimil Babka wrote: > On 3/2/20 8:36 PM, Minchan Kim wrote: > > From: Oleksandr Natalenko > >=20 > > 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: > >=20 > > * use LD_PRELOAD; or > > * patch the kernel with something like UKSM or PKSM. > >=20 > > (i skip ptrace can of worms here intentionally) > >=20 > > To overcome this restriction, lets employ a new remote madvise API. Thi= s > > can be used by some small userspace helper daemon that will do auto-KSM > > job for us. > >=20 > > I think of two major consumers of remote KSM hints: > >=20 > > * hosts, that run containers, especially similar ones and especially = in > > a trusted environment, sharing the same runtime like Node.js; > >=20 > > * 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. > >=20 > > 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 instanc= e > > depending on the amount of tabs. > >=20 > > 1 FF instance with 15 tabs: > >=20 > > $ echo "$(cat /sys/kernel/mm/ksm/pages_sharing) * 4 / 1024" | bc > > 410 > >=20 > > 2 FF instances, second one has 12 tabs (all the tabs are different): > >=20 > > $ echo "$(cat /sys/kernel/mm/ksm/pages_sharing) * 4 / 1024" | bc > > 592 > >=20 > > 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. > >=20 > > [1] https://lore.kernel.org/patchwork/patch/1012142/ > >=20 > > Reviewed-by: SeongJae Park > > Signed-off-by: Oleksandr Natalenko > > Signed-off-by: Minchan Kim >=20 > This will lead to one process calling unmerge_ksm_pages() of another. The= re's a > (signal_pending(current)) test there, should it check also the other task= , > analogically to task 3? Do we care about current there then? Shall we just pass mm into unmerge_ksm= _pages and check the signals of the target task only, be it current or some= thing else? > Then break_ksm() is fine as it is, as ksmd also calls it, right? I think break_ksm() cares only about mmap_sem protection, so we should be fine here. >=20 > > --- > > mm/madvise.c | 4 ++++ > > 1 file changed, 4 insertions(+) > >=20 > > 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) > > =09switch (behavior) { > > =09case MADV_COLD: > > =09case MADV_PAGEOUT: > > +#ifdef CONFIG_KSM > > +=09case MADV_MERGEABLE: > > +=09case MADV_UNMERGEABLE: > > +#endif > > =09=09return true; > > =09default: > > =09=09return false; > >=20 >=20 --=20 Best regards, Oleksandr Natalenko (post-factum) Principal Software Maintenance Engineer