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=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT 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 378F2C2BA83 for ; Fri, 14 Feb 2020 17:06:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F2D6B24650 for ; Fri, 14 Feb 2020 17:06:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tjv0/8H5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2D6B24650 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A37486B0653; Fri, 14 Feb 2020 12:06:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C0E96B0655; Fri, 14 Feb 2020 12:06:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 887926B0656; Fri, 14 Feb 2020 12:06:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0069.hostedemail.com [216.40.44.69]) by kanga.kvack.org (Postfix) with ESMTP id 656D76B0653 for ; Fri, 14 Feb 2020 12:06:40 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 01E0E8248076 for ; Fri, 14 Feb 2020 17:06:39 +0000 (UTC) X-FDA: 76489361760.02.map29_916ba397b632c X-HE-Tag: map29_916ba397b632c X-Filterd-Recvd-Size: 5902 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Fri, 14 Feb 2020 17:06:39 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id y73so5186351pfg.2 for ; Fri, 14 Feb 2020 09:06:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QW1XPYsqgB39eZebwl/0zlcNp074EgOP5RJbtqrekRI=; b=tjv0/8H5C4Q/P1CI4cMR+BGXtWyW85rmKZmanW8HGhITwLhPbQWFNhHgGWNwfUZgbS Q3Ds+v9zX14E43xMVdfMkET1cjZr0SG6/okyVsha5tB67+3fCOgLaK9a/3zixj5dumXV EwkFFlBhntJR+z+QnAeuBU+WzLNCx921Oz12VOiunXgMR2idXeMVhUwFBww8Eky1hLYC gQdOIWHJa3AxDPvShHWfx1sbbHqQFjKQdjvezK9XlCZr+5kdh7Fg1Xx6vjqHkQfRNzra i/RgKelzECG0vCdgocqy1TBiiNxyeI3lz4ztEGQf6mnCztYzpPycUlxBjfSlRbHW8u+V SJ9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=QW1XPYsqgB39eZebwl/0zlcNp074EgOP5RJbtqrekRI=; b=UN2xNSCMSkKWpw0GxY8A6ZVjd4CavncrJ2r05wI87gYAfeLnrHX4G/1LT4cFdZZdwZ FBYlxAYXRQNCmBvwN53PBhdFhIeBu/H56TIHUzBuXssEW/bjOjI4QQ8edL6i2Q8gy3T2 PoGuBY8Ws6kdoA2F+XiwMzlFgs8QiHhdRl2CdoPjk1pVeh0CjzwKwchfdBksTb6yyrGv 2p3yTBa3ub7SDYzp8wRO8WAlir4abhL3pTqWr/gMnoKfj8eU4Ebv9SRePRb8NRkZJ0K6 cHLYtbA2TiHCoRqSgLyKAMA4MqgjlVNeeG3shLife1uOTrtfp/xLlVMPxj/3Xp1Qgb8E GoJA== X-Gm-Message-State: APjAAAU//oYRS2TphBCLvvhOtG7rSYfKao9mHbnZA2rLYlouXDmuD4gg KdPotzmzhvJMFRCxhhHkU8Y= X-Google-Smtp-Source: APXvYqzPa9D1Lmoi4ZgRT/Il+guBGFLg4E8qSkXjuDrKMdjBDKsbzorml+cGx3N3NMnTf7FbxXP7tw== X-Received: by 2002:a63:4b65:: with SMTP id k37mr4615617pgl.46.1581699997969; Fri, 14 Feb 2020 09:06:37 -0800 (PST) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:1:3e01:2939:5992:52da]) by smtp.gmail.com with ESMTPSA id a13sm7662924pfg.65.2020.02.14.09.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 09:06:36 -0800 (PST) From: Minchan Kim To: 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 , sj38.park@gmail.com, alexander.h.duyck@linux.intel.com, Jann Horn , Minchan Kim , SeongJae Park Subject: [PATCH v5 7/7] mm/madvise: allow KSM hints for remote API Date: Fri, 14 Feb 2020 09:05:20 -0800 Message-Id: <20200214170520.160271-8-minchan@kernel.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200214170520.160271-1-minchan@kernel.org> References: <20200214170520.160271-1-minchan@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: 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 b= e 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 --- mm/madvise.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/madvise.c b/mm/madvise.c index 762a68205e65..0ecacfe93166 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1004,6 +1004,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; --=20 2.25.0.265.gbab2e86ba0-goog