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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 838CEC33CB1 for ; Tue, 28 Jan 2020 00:17:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B2FE24695 for ; Tue, 28 Jan 2020 00:17:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580170630; bh=aMYXWhng/JnEG6oCT//2c8g6lC5FwwpptVP3GXeSSMA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=fdY1YuisX4CmblXd1JOAJHc9K7uijbLNoyrZ7AX933xXSxbSK3ItLLth6crzOPspc JnE57pq+1BNVBzvqfYgsAzIWAVV6Y4JD0VwXSN+evWvb0Boy6O+8rY8B0vvug6pIrW EUi9CHBPCaiqstP3OOzhD4zK7Vl7Pgxp0l1t8arw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727773AbgA1ARJ (ORCPT ); Mon, 27 Jan 2020 19:17:09 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:44440 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727161AbgA1ARE (ORCPT ); Mon, 27 Jan 2020 19:17:04 -0500 Received: by mail-pf1-f193.google.com with SMTP id y5so2626286pfb.11; Mon, 27 Jan 2020 16:17:04 -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=byMHrtK1k5FQWktxNZKgpIEhIdZ+jOjWAb7BIyi4lBA=; b=gcx1AwE/bXt90sOnHE8tkitJggiidEQCzgaEc9elcFPregk1F09926WnR6sPAg3NHJ mIdBVj3BsjX81nGowuT7nAHRs/GrhviVJ0DG0ewbqf9nFz7NW9teL64pZ80eInjpolPq tt9YXVZIlEnxXxs3ICAKN+eSUjOOAUjpIiPgAi6cSZGda3zZyEN1/53WSOo3HCGu4l9/ G0DIYIfxA5E7gL/I1DcIRTTnJgrEP+6HhyO/1n2jPWRNKAeF6JjqwMi/diaeEbctuQxz 8C/6+fIHhoD0HaL7Cugo9ZHJUBLrc+HiU4S3OW9lz1c1njwkgnk1GWxa564lMnoHTJP9 oNXw== 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=byMHrtK1k5FQWktxNZKgpIEhIdZ+jOjWAb7BIyi4lBA=; b=s7jNU4MDJ0eBy3ln9TBRXF93Ub1rMgaUL5L64QZp46qdVIE/Zdg6V6f7/C9YanSpMM pub4RzMZwwEOV1D+1YxYvDIkh7/m6j0/IFRc6rdG3pPGML5ctY3O6cICpZVDEuBMABci qGBKKdGe9IQsSKTY09mRROAQ4qKpBckoR8Q267IAWcAYLb+qJsPnBo5nCu6cjCDNHXcX 4buCsc2r7vissgIsg5jADogjHh5dMDh3oGgMJu+n22JKlMraopH14aJEWZgisHiaio7b 22GghpkO+dXKMvy1ai9GtWnCLoNs25bmT+wYqS+TyDIL72qyl8TQVFaq+CgHhKYkFTMq QzYA== X-Gm-Message-State: APjAAAWCJBl6QtuLVdDpZQVM02LBXSq3yNunJqY/Yd5zhxBRSR9foZpJ isHoeBpZwyyv/tk8yXcfpdQxfAey X-Google-Smtp-Source: APXvYqx9+zAHx+aMRolYkWKe8SUK4zOvH2qwG7qZk5YBG1aQfIomoeisjAxibGaMfQWIJ4KB7xfjJA== X-Received: by 2002:aa7:9a96:: with SMTP id w22mr1189196pfi.210.1580170623768; Mon, 27 Jan 2020 16:17:03 -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 q28sm11301461pfl.153.2020.01.27.16.17.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 16:17:02 -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 , Minchan Kim Subject: [PATCH v3 4/5] mm/madvise: allow KSM hints for remote API Date: Mon, 27 Jan 2020 16:16:40 -0800 Message-Id: <20200128001641.5086-5-minchan@kernel.org> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200128001641.5086-1-minchan@kernel.org> References: <20200128001641.5086-1-minchan@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/madvise.c b/mm/madvise.c index bc0a72dbf80e..39c40cbb389e 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1002,6 +1002,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; -- 2.25.0.341.g760bfbb309-goog