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 1CA84C33CAF for ; Fri, 17 Jan 2020 00:00:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C6540207E0 for ; Fri, 17 Jan 2020 00:00:16 +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="f5kcC/lG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C6540207E0 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 490D86B000A; Thu, 16 Jan 2020 19:00:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4412C6B000C; Thu, 16 Jan 2020 19:00:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3585D6B000D; Thu, 16 Jan 2020 19:00:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0103.hostedemail.com [216.40.44.103]) by kanga.kvack.org (Postfix) with ESMTP id 1BB4B6B000A for ; Thu, 16 Jan 2020 19:00:13 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id A326A180AD817 for ; Fri, 17 Jan 2020 00:00:12 +0000 (UTC) X-FDA: 76385168664.09.coat12_1ed4753087e58 X-HE-Tag: coat12_1ed4753087e58 X-Filterd-Recvd-Size: 5773 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Fri, 17 Jan 2020 00:00:11 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id 2so11027462pfg.12 for ; Thu, 16 Jan 2020 16:00:11 -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=H8HMvNtR0Yr/0G1kCuWPpE/efrXm+U1USbROvI8CFic=; b=f5kcC/lGcofak/wnm8eHOoKUvo+na2iOkPkZSKjqqaIzJ+5aVFD4TEUor6ereTvJ6p t5txXIGg3oxL68CnlMHNsUIX2WksBfEDXcHaS8xiID24bQSKYIR3BQRc5MAZx3DJh09r mar5HOv6MBzYpoE9rqTWdm5z8iYPIqzSRGhQvyqj5t+CyU8u99n7R2eF5f65n2wV9mFr HYud3Ysipql4mKy+NCvR2emo38TC7DKLI+V+/jC+F0cNWpve0fI+B91XUTvupOZCwSDh GwzYLNsi2UhYaxLj5j7SHKyI2lMlA+qCrxwUmV7K7yJZkuNIVpvj9MQs1AclKJy8DxbT ZV7w== 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=H8HMvNtR0Yr/0G1kCuWPpE/efrXm+U1USbROvI8CFic=; b=Q2Tt8JSeE4zp/TvxBNHV6mzsnxKRLA2xblMbLlmCUcCGiCQe1wxOC2NZwvSizQqR/g booWI7LMuyHO/JCKWAxMGBHqfayEUZi4o71YTokiQsNHFQBLGyVnCjv+SBGFv0RY0TIN G+rjPZ2kSkOzYaNgvl6Hnq2bEs0XLyLwsHJgaorMi64Tztn9BJAzk+W3yIx3XtOzcSpH wW1h4MHQ2fDBXj8eSXFYzdtCpO2AC1hbe8CZRjeP5SnOwd68lWuRudR5lzEAUxJFhfIv r//COaIs+q3/01fEXKi+lojUwHWRJUrzGaIvJjEbr1IyBdh3omKwOUNRPDz+pD6lZhPR aMBw== X-Gm-Message-State: APjAAAXbw519NapZpp1ZbzkKuI6EUZPjfnRYhT4m9K00CMhl58AMkr7H ej82S+y29L6DDPCFks0R6DY= X-Google-Smtp-Source: APXvYqzvDAAr4MbHD2POg6JtSQKZAHaHXfFxw1HvbzcRnW/RCA5AvGamnLqnrWS5xbRpI1SF+CmhKg== X-Received: by 2002:a63:f202:: with SMTP id v2mr41667379pgh.420.1579219210884; Thu, 16 Jan 2020 16:00:10 -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 z4sm26584885pfn.42.2020.01.16.16.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2020 16:00:09 -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 , ktkhai@virtuozzo.com, christian.brauner@ubuntu.com, sjpark@amazon.de, Minchan Kim , Minchan Kim Subject: [PATCH v2 4/5] mm/madvise: allow KSM hints for remote API Date: Thu, 16 Jan 2020 15:59:52 -0800 Message-Id: <20200116235953.163318-5-minchan@kernel.org> X-Mailer: git-send-email 2.25.0.rc1.283.g88dfdc4193-goog In-Reply-To: <20200116235953.163318-1-minchan@kernel.org> References: <20200116235953.163318-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/ Signed-off-by: Oleksandr Natalenko Signed-off-by: Minchan Kim --- mm/madvise.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/madvise.c b/mm/madvise.c index 84cffd0900f1..89557998d287 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1000,6 +1000,8 @@ process_madvise_behavior_valid(int behavior) switch (behavior) { case MADV_COLD: case MADV_PAGEOUT: + case MADV_MERGEABLE: + case MADV_UNMERGEABLE: return true; default: return false; --=20 2.25.0.rc1.283.g88dfdc4193-goog