Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp6845632ybf; Fri, 6 Mar 2020 05:43:19 -0800 (PST) X-Google-Smtp-Source: ADFU+vuhm9noEwHLEuvN0Cx4YS1j2cWrZtFIK/skaWoaCcoMYO3XPF0++uZkkyTccdnLc7d5A5k4 X-Received: by 2002:aca:ed58:: with SMTP id l85mr2551778oih.70.1583502199616; Fri, 06 Mar 2020 05:43:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583502199; cv=none; d=google.com; s=arc-20160816; b=xGlgW+0+119fsliNw5vO1EdcrAd7LSlX7hU2t5W90Ptv4TkkQ/z8AJlN6EbLMW4ZOS AjhiHkfobYA/2/NcWD6/TD15Y+KBbRLafTXYFP+l9OcaGQj3W1HGNygc70iLTBKSz4r1 24F8JdbcZEJ4+4lUvUBvs943eRw12NbQt5vfCauHOewaDEiU/fki4BMZMUIaC5/74J32 TJfbioQFOFTEUhWdmPJ6C85O4B8DuxMI5Dg9CtAW37O1JuKuWX+IdkCueLgpF6ONXu3+ jPSx108eAIu+krMh3HZ/IgHWIjsU5vNr4epD+g9BWaIWpuSd+pofwqvfQiIOOct8DHgm 0hCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=IEMTcz44qXHTvt90A4c5VFOdWnApL2YdhivNGIEppTM=; b=p21ZBxbjoct5Z8G3xCo1E2aF8J0NY1u9WtOPVwt1UGXiWUO66kNFC4o2jccW+LDZVk NBKm1A/l56G4VMQ1RMNuERfk75JCUGMz5DeXbpHi4B6HIVmu11VlY2wUhiv5iIos3C7t wpU6gRdDtHGGAuZu13NjB2WpUCWVbF4unRbnVBrdOxi8c3MkkEYOrI7ej6ltghsVjQ1R GiM1oArW5W23is+B/3r9I5pTNf+pt/hdtiDHhcsgpw+Xy7tnTtIYypXc8GFeXFweUu4Q 3+tepO5twaQGNRUygcu2lwn+9xDU1JLT11YOQ/mDk83ai5ahp78m33V7q3X2VPGd0GoI r1EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G2t9qaDe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v81si1369358oia.114.2020.03.06.05.43.07; Fri, 06 Mar 2020 05:43:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G2t9qaDe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727125AbgCFNly (ORCPT + 99 others); Fri, 6 Mar 2020 08:41:54 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:49673 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726733AbgCFNly (ORCPT ); Fri, 6 Mar 2020 08:41:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583502112; 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: in-reply-to:in-reply-to:references:references; bh=IEMTcz44qXHTvt90A4c5VFOdWnApL2YdhivNGIEppTM=; b=G2t9qaDew01uHLoN99L/nWH/WmfEG/Tu20WnyLldLeacxskqR6P/x0NkxCM2aV3NDl/Cuq 7GNGlhV5L9HvGDTJYbrHmaxDAxjSZ34sfMgLk7cxgKO9/YZDRUTlIc273WqpNR812mz7q9 OKuf+GEjGvOcUJRv4UFSXf52KVS7tv0= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-363-nqV6Rpd8MOayWjtO4FUMGg-1; Fri, 06 Mar 2020 08:41:49 -0500 X-MC-Unique: nqV6Rpd8MOayWjtO4FUMGg-1 Received: by mail-wm1-f70.google.com with SMTP id d129so903314wmd.2 for ; Fri, 06 Mar 2020 05:41:48 -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=KusUXVS9UFUQNk5Aw/e9/X5ATceTxjLWs5Fpetayk/8diPsT9cubCBX31dAzVpZjxT mj3VPFCB9lzRyY7r9/1wcqUyGRpQxtBNy3Q4dFJRDIJzEdV+LvoRnoWxJV+AvsqaLHec ScdGzVR0uqJVucmIpiroin6HJWxiXYX0Yi0YTRq3TkofKXK/Lv0viZPFhRq354AQcFXU G1xED9teJOqzFfZnQOxOblVHXb7L/AEVxqAyWVkmXE4VXNc4F9+hm4hX/DHuK8Rpk8Vr e1seLhRplisRTM9Q73D29h86O8mjczaiRkXv9n4HHXcIDoOVSj9VVFNYM4gq3ioSY3Rf kL/w== X-Gm-Message-State: ANhLgQ2oo0DOG31MDpC/ulZEnm/9wHsEnAqvmKsgf9O/p7lJrC69MFEN g40OjoNtaUfq8+U4RjQJrgKH/pkO8vPZVLsrb/V363HIm3UAyz5qlQ9qYRKOCIl/3vm70ILfBXE c8hT69y8YrcxQc1YqWXsJ19kE X-Received: by 2002:a05:6000:8f:: with SMTP id m15mr3969854wrx.378.1583502107829; Fri, 06 Mar 2020 05:41:47 -0800 (PST) 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2a66abd8-4103-f11b-06d1-07762667eee6@suse.cz> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > > > 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? 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 something 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. > > > --- > > 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; > > > -- Best regards, Oleksandr Natalenko (post-factum) Principal Software Maintenance Engineer