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 5BDF0C38142 for ; Tue, 31 Jan 2023 13:57:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACA996B0078; Tue, 31 Jan 2023 08:57:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A539C6B007B; Tue, 31 Jan 2023 08:57:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F3D86B007D; Tue, 31 Jan 2023 08:57:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7BFDB6B0078 for ; Tue, 31 Jan 2023 08:57:27 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2C83D14073B for ; Tue, 31 Jan 2023 13:57:27 +0000 (UTC) X-FDA: 80415246534.15.0DC81F4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf25.hostedemail.com (Postfix) with ESMTP id F3CADA0016 for ; Tue, 31 Jan 2023 13:57:24 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QZhPvOse; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675173445; h=from:from:sender: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:dkim-signature; bh=KLzrEVNF/I06hEyCLzFWZ+B0+c4Uy25WE0TJqoTLRzw=; b=8rC0yGuNct5EwuSdnMNa1WAloUJbMgqqaqTdkJGF2gSxDcTvXF3TQdTXvQ9RelMWckQ1ce zIUZnfZpO79T9K9obXdV969omAjeobyh1V+V1WcZ42pNNgx/qzrEuwh/jpjBbzNVxhwsWq CAsIOy1XDqU/4d4Piov3QC714EakNW4= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QZhPvOse; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675173445; a=rsa-sha256; cv=none; b=s8opbC9NnPXrnB9t++pv2jN53Y2j9+D1pZAY2xPdjQ2KNKv5xuB5Tdh1nj6fXGQwziHRNz NZ2a6wNn6mZAldDYd6uu6A0DkZAGETW/mlrBzW7BlqGLPET2DX2adbM7+g2n9pcK8Zhm0I 7YoTJsecwY//DzMM0kIbYB+XdVZxjb8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675173444; 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=KLzrEVNF/I06hEyCLzFWZ+B0+c4Uy25WE0TJqoTLRzw=; b=QZhPvOsekA/DBfoNj2jeVyTVltGiqTznKirizv35Yu+eXGM2UwO4/gWDXK+l07lDkX6Rxh 3GD6hIzrZFGpWP3zQY9TEjM80su8/cSZTdUVih6LjDnAc5ot4ycAzfAd7kvgo7KVzIc9Us PuYBvtkzOBdp7nV1X5ClVmRnyjPZkWQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-650-hyVFd9FuPYCKxPLZq7yLXA-1; Tue, 31 Jan 2023 08:57:23 -0500 X-MC-Unique: hyVFd9FuPYCKxPLZq7yLXA-1 Received: by mail-wm1-f72.google.com with SMTP id x10-20020a05600c21ca00b003dc5584b516so4286436wmj.7 for ; Tue, 31 Jan 2023 05:57:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KLzrEVNF/I06hEyCLzFWZ+B0+c4Uy25WE0TJqoTLRzw=; b=1h+648IEHEHg63GU1Rq0Gg1c+xqEnJ1ZCwjEF+Y+xfLOB0GlOE+/TDTwtIze4n2iWt GejhGwdDLSVccZUyH27GkOD8D9Od9IqkFQEhOttc0mMrYRXKuPvq9gnvTdzCjTNYCmZ4 uOGSfocUT0Qam8rWD7J5fkkOzETKTExQaWwnca4UbrrhPNTIO8KIm9Iocqcr5UKuLgd3 wejJ51mFsjxQyodP0gEC8cUQYyEB3g3JP3Lh7Iy1jnGDLAk6rVPICXa8eLjg2vbKTp6I Y+tkLA7b2Tz5SDgQyqe18peZwJiaLzSqVjljPJ5+/A45ii8dFeGRI9DYmbQskLL66qCv paRw== X-Gm-Message-State: AFqh2kpMwXbfNcZhlYqE5Yn7OyR+mkg/E2Z2xVUEJG+/C2GP89zb8sK7 qqFuIE4IniIHfotOHhLdmqa0gi70/QrIHHgTAd9yvcU982AlelmFdzbsw/vDiwJ5xvjjBcj3gID UNpKk3owXLVw= X-Received: by 2002:a05:600c:4e03:b0:3db:262a:8ef with SMTP id b3-20020a05600c4e0300b003db262a08efmr44560335wmq.38.1675173442173; Tue, 31 Jan 2023 05:57:22 -0800 (PST) X-Google-Smtp-Source: AMrXdXsjRC03EHs1ylOUCt2idLp4HzZmJ3Ve19/uWBVh0SsYpLR/66FyQTj2vCIacfH10/YwThbP4g== X-Received: by 2002:a05:600c:4e03:b0:3db:262a:8ef with SMTP id b3-20020a05600c4e0300b003db262a08efmr44560307wmq.38.1675173441825; Tue, 31 Jan 2023 05:57:21 -0800 (PST) Received: from ?IPV6:2003:d8:2f0a:ca00:f74f:2017:1617:3ec3? (p200300d82f0aca00f74f201716173ec3.dip0.t-ipconnect.de. [2003:d8:2f0a:ca00:f74f:2017:1617:3ec3]) by smtp.gmail.com with ESMTPSA id f28-20020a5d58fc000000b002be5401ef5fsm15330455wrd.39.2023.01.31.05.57.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 31 Jan 2023 05:57:21 -0800 (PST) Message-ID: <6369225e-3522-341b-cd20-d95b1f11ea71@redhat.com> Date: Tue, 31 Jan 2023 14:57:20 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [RFC PATCH 00/19] mm: Introduce a cgroup to limit the amount of locked and pinned memory To: Jason Gunthorpe , Alistair Popple Cc: linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, jhubbard@nvidia.com, tjmercier@google.com, hannes@cmpxchg.org, surenb@google.com, mkoutny@suse.com, daniel@ffwll.ch References: From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: F3CADA0016 X-Stat-Signature: 68dh6ew54i7d8j63z981ysohhua5zb4z X-HE-Tag: 1675173444-727421 X-HE-Meta: U2FsdGVkX1/57yN/cM8XrOptPGDdwcsWfjz4RYQZmB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KkpnnqLwB2ywfjflK+pSFA2/xhF+sj46XdhoJplj/UmV7vnvCwi2flQFYQvWi8S5vJugcf8gIsSgP1XCQnBL7fTnIJNlB1BZXtLQ0KMOTlklq/0DTYm9XDU/Hi20Xnk2vhA4HsP/xUeerpFqkCSJ4PNjUjlIAA/QMPa/1h0oZ7ixI0N5bBkEQZRH/f22+0MAUifJDE1S1LzcCsOyEGP7FcyJEDttsGJBrEzcvLIaFNp0gbfnpHemDYYpsgayFnYiTz21RhGpPrpNpteXIZf4g0+k6vnIjftnoWlQSVTyPh/c5VWw7L6fTnPgo0D/KsoBPP/nALwNJ3Vn/DvWmp2UDRqxIMQ== 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 24.01.23 21:12, Jason Gunthorpe wrote: > On Tue, Jan 24, 2023 at 04:42:29PM +1100, Alistair Popple wrote: >> Having large amounts of unmovable or unreclaimable memory in a system >> can lead to system instability due to increasing the likelihood of >> encountering out-of-memory conditions. Therefore it is desirable to >> limit the amount of memory users can lock or pin. >> >> From userspace such limits can be enforced by setting >> RLIMIT_MEMLOCK. However there is no standard method that drivers and >> other in-kernel users can use to check and enforce this limit. >> >> This has lead to a large number of inconsistencies in how limits are >> enforced. For example some drivers will use mm->locked_mm while others >> will use mm->pinned_mm or user->locked_mm. It is therefore possible to >> have up to three times RLIMIT_MEMLOCKED pinned. >> >> Having pinned memory limited per-task also makes it easy for users to >> exceed the limit. For example drivers that pin memory with >> pin_user_pages() it tends to remain pinned after fork. To deal with >> this and other issues this series introduces a cgroup for tracking and >> limiting the number of pages pinned or locked by tasks in the group. >> >> However the existing behaviour with regards to the rlimit needs to be >> maintained. Therefore the lesser of the two limits is >> enforced. Furthermore having CAP_IPC_LOCK usually bypasses the rlimit, >> but this bypass is not allowed for the cgroup. >> >> The first part of this series converts existing drivers which >> open-code the use of locked_mm/pinned_mm over to a common interface >> which manages the refcounts of the associated task/mm/user >> structs. This ensures accounting of pages is consistent and makes it >> easier to add charging of the cgroup. >> >> The second part of the series adds the cgroup and converts core mm >> code such as mlock over to charging the cgroup before finally >> introducing some selftests. >> >> As I don't have access to systems with all the various devices I >> haven't been able to test all driver changes. Any help there would be >> appreciated. > > I'm excited by this series, thanks for making it. > > The pin accounting has been a long standing problem and cgroups will > really help! Indeed. I'm curious how GUP-fast, pinning the same page multiple times, and pinning subpages of larger folios are handled :) -- Thanks, David / dhildenb