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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8D75C433F5 for ; Thu, 25 Nov 2021 08:39:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 667D46B0074; Thu, 25 Nov 2021 03:39:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6182F6B0075; Thu, 25 Nov 2021 03:39:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E0596B007B; Thu, 25 Nov 2021 03:39:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0058.hostedemail.com [216.40.44.58]) by kanga.kvack.org (Postfix) with ESMTP id 3ED236B0074 for ; Thu, 25 Nov 2021 03:39:34 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 02D8885D52 for ; Thu, 25 Nov 2021 08:39:24 +0000 (UTC) X-FDA: 78846803658.05.756F317 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 4BC457001702 for ; Thu, 25 Nov 2021 08:39:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637829562; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iUYjBkHGKOvo0IUPqV039+uB0R59hc4+zlXw+bbyRX4=; b=ZWHNvsp6JdsjyBWY9HL/MUr+mQe3a2vJk+3jlKGNZB7D0p5wSO7p2ZyyFW+GAEr1o2y81O PFphU3o4yWu2NuDLlaLUJnfFwPf5LvKZxGYC3ntUhsXej5YdjW67TzjfZL4QuwfkgS2AiW mS0+aJSKRcp6GW+m1DFzGVvtF/XyXws= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-238-H_zU0ef-Pgi478BHIRo35Q-1; Thu, 25 Nov 2021 03:39:21 -0500 X-MC-Unique: H_zU0ef-Pgi478BHIRo35Q-1 Received: by mail-wm1-f70.google.com with SMTP id r129-20020a1c4487000000b00333629ed22dso4550621wma.6 for ; Thu, 25 Nov 2021 00:39:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=iUYjBkHGKOvo0IUPqV039+uB0R59hc4+zlXw+bbyRX4=; b=4kQ/FNQdis+hFW0gnLD5EpMM1fjXmLfsjMIwAGSvKNfXvQC2NwPZ5jdcTLAY6Y4RNo 4Z/54+kfbsTFZ9OCQc8BVRfnfbtoDtr9JluKhtbnvG0LGjyoXTM9+7TjEITEIRrykw+O 07gUDspxu9XuJjdfqOydbDlyLZ71j2pCBskPTfMOWPJjydCoFjo2HKzTVE/zP5/HBkZe nR0u2KDkcX+erEbXLx1gNy8KG9obpvcD7BK0EKqJFPKHBb+y4TaoPP2PYX700BUi8VD7 wbTxwpgUKOlvSyqIT07YEckeExAqAUh157hk8qGEVbTQL5X9FBpTOX5nxbyFEBBBwln7 cMMA== X-Gm-Message-State: AOAM533UfKVQEGKoGJLYLavoivlb9DmTCv6iV5yWetGRh1IsbuNNZ0gI VJnDcdu41UcFsWPqyG2TWRrN0hqpa2y7uM4GUYfm7LBq8QL2QYUn6lAzp2AjXIhngUoVOYsMWKU XvyUxhkfEh/8= X-Received: by 2002:a05:600c:4e94:: with SMTP id f20mr5035991wmq.119.1637829560207; Thu, 25 Nov 2021 00:39:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJzo7sO2xOaIAYA/0e+RElMZ67idmGfmI2SrHj7Ck8MGlXcVY6l6jqfyhvPK+/PH/b2vGQiKXw== X-Received: by 2002:a05:600c:4e94:: with SMTP id f20mr5035959wmq.119.1637829560011; Thu, 25 Nov 2021 00:39:20 -0800 (PST) Received: from [192.168.3.132] (p5b0c679e.dip0.t-ipconnect.de. [91.12.103.158]) by smtp.gmail.com with ESMTPSA id l5sm2715361wrs.59.2021.11.25.00.39.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Nov 2021 00:39:19 -0800 (PST) Message-ID: Date: Thu, 25 Nov 2021 09:39:18 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 To: Shakeel Butt , "Kirill A . Shutemov" , Yang Shi , Peter Xu Cc: Zi Yan , Matthew Wilcox , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20211125024523.2468946-1-shakeelb@google.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v2] mm: split thp synchronously on MADV_DONTNEED and munmap In-Reply-To: <20211125024523.2468946-1-shakeelb@google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4BC457001702 X-Stat-Signature: g7qtgteoq8rxanjnkij5cxmafp6k5rcp Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZWHNvsp6; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf02.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam02 X-HE-Tag: 1637829561-885745 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: On 25.11.21 03:45, Shakeel Butt wrote: > Many applications do sophisticated management of their heap memory for > better performance but with low cost. We have a bunch of such > applications running on our production and examples include caching and > data storage services. These applications keep their hot data on the > THPs for better performance and release the cold data through > MADV_DONTNEED to keep the memory cost low. > > The kernel defers the split and release of THPs until there is memory > pressure. This complicates the memory management of these sophisticated > applications which then needs to look into low level kernel handling of > THPs to better gauge their headroom for expansion. > > More specifically these applications monitor their cgroup usage to decide > if they can expand the memory footprint or release some (unneeded/cold) > buffer. They uses madvise(MADV_DONTNEED) to release the memory which > basically puts the THP into defer list. These deferred THPs are still > charged to the cgroup which leads to bloated usage read by the application > and making wrong decisions. In addition these applications are very > latency sensitive and would prefer to not face memory reclaim due to > non-deterministic nature of reclaim. > > Internally we added a cgroup interface to trigger the split of deferred > THPs for that cgroup but this is hacky and exposing kernel internals to > users. This patch solves this problem in a more general way for the users > by splitting the THPS synchronously on MADV_DONTNEED. This patch does > the same for munmap() too. > I'll have to defer diving into the code. Just a comment: It might be good to add that there are still cases where splitting the compound page can fail -- for example, if the page is still pinned/referenced. So if you have a THP and intended to only pin/reference e.g., the first 4k of it (e.g., O_DIRECT, io_uring fixed buffers), MADV_DONTNEED/unmap e.g., the last 4k of it will not split synchronously. In addition to explicit user action on a compound page; I remember there might be other kernel-internal temporary references that could theoretically block splitting, but maybe most of them are at least for now limited to !compound pages. -- Thanks, David / dhildenb