From patchwork Thu Jan 16 23:59:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 11338037 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A03A7921 for ; Fri, 17 Jan 2020 00:00:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6C28B207E0 for ; Fri, 17 Jan 2020 00:00:18 +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 6C28B207E0 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) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4412C6B000C; Thu, 16 Jan 2020 19:00:13 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org 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-Original-To: linux-mm@kvack.org 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-Spam-Summary: 30,2,0,86404a0842d2d401,d41d8cd98f00b204,minchan.kim@gmail.com,:akpm@linux-foundation.org:linux-kernel@vger.kernel.org::linux-api@vger.kernel.org:oleksandr@redhat.com:surenb@google.com:timmurray@google.com:dancol@google.com:sspatil@google.com:sonnyrao@google.com:bgeffon@google.com:mhocko@suse.com:hannes@cmpxchg.org:shakeelb@google.com:joaodias@google.com:ktkhai@virtuozzo.com:christian.brauner@ubuntu.com:sjpark@amazon.de:minchan@kernel.org:minchan@google.com,RULES_HIT:41:355:379:541:800:960:967:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1542:1711:1730:1747:1777:1792:2393:2525:2559:2563:2682:2685:2693:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4823:5007:6119:6120:6261:6653:6742:7576:7901:7903:8557:9025:10004:11026:11658:11914:12043:12297:12438:12517:12519:12555:12679:12895:12986:13869:13894:14181:14394:14721:21080:2122 2:21444: 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 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 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/ 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;