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 29357C636CC for ; Thu, 16 Feb 2023 11:01:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B7266B0071; Thu, 16 Feb 2023 06:01:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 967206B0072; Thu, 16 Feb 2023 06:01:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82F116B0073; Thu, 16 Feb 2023 06:01:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 71F356B0071 for ; Thu, 16 Feb 2023 06:01:51 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id EF3E11C2814 for ; Thu, 16 Feb 2023 11:01:50 +0000 (UTC) X-FDA: 80472864780.30.4319BA4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 4762C4002C for ; Thu, 16 Feb 2023 11:01:48 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="FVn8S7/2"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676545308; 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=RT3I0H8bP1HeewuPOTi34AMMwE+sGnWigdoFWwsEuUo=; b=18xwelfzEnQh8SsnAez5X/ghZr+KF5agudAzx3aLhL55AG6pEjjLUUPG08h8FDCFHhq8/m wMYS+gWg8AW7V1ec2Pc8TRyaTDudZyKg4F/YZn/oCDHY9GjWNHM/w/cj+OgL5H3jFGsvDU 9/DCWp+sA4GZGwAs6zTceRXs/yuwFWk= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="FVn8S7/2"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676545308; a=rsa-sha256; cv=none; b=wMcmIchkmUMMTy3VW+N4Bqu1Qv+eA4ywhSBytFD6TIgerySL5WActcCs0QZZBT/PdFQtXG NEIMlXwxXLsyYQVjC2plqu4OuljrQ0zvKFJvJPQuODQEEEH8vf756Z8xhK+TsiAnx4uU/T J/Rs0LHbQuQDH3p4EE9y06CukXXXRs8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676545307; 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=RT3I0H8bP1HeewuPOTi34AMMwE+sGnWigdoFWwsEuUo=; b=FVn8S7/2Wj28Zj0Ty1m6tPXTbIeBn3wHG7D2mh1enYTMRiwyJi2XjzoySHrRVm1Nhpry4l GdNVwPDiRlv8FgHi+4sMWpow1yIzs+KVMgUR/1emLCZUbmmBUsempa9hnN7aut/o+D+YmR PLayxokyW78umRIko8Gc1ISqeAY8drk= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-26-fwJlpjcDPOuS3PKKQrzeQg-1; Thu, 16 Feb 2023 06:01:46 -0500 X-MC-Unique: fwJlpjcDPOuS3PKKQrzeQg-1 Received: by mail-wr1-f70.google.com with SMTP id y3-20020adfee03000000b002c59b266371so45873wrn.6 for ; Thu, 16 Feb 2023 03:01:46 -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=RT3I0H8bP1HeewuPOTi34AMMwE+sGnWigdoFWwsEuUo=; b=YIBRyFPqIYLB7u49O9puI0nCHesrpU2X8SQnRvNmdGyiaHv5gOhtEx8cSWsDpuXnA8 GCekrLn/emfJFi6aE1WKnXfFozqsiVwLv0hegdBorsbygw+0XGXsJ1O0/WKzBO5pPWqP NW2jtLita/iElaL+EgwFXTIYlv3815fBpCWvcO74a7KI3Y5+4iVladoE0n5KeadOso1N LUYmn3xe7clLCo0gqcKKECOPHr8DPVdlcMPOjilPrqEESnYAjWTGYrXvnXBzN76/RQqy pU2+Kr2MNN2Ssa8KOGZd1+jgx50Eg8exAEywAfPMlVlSlzoPqXHLlaO7RoYcsrc1lvNZ dwdQ== X-Gm-Message-State: AO0yUKWp+YQtf/HVgqUjxLsQTIDpTkdJ3QyEo5+SZwXu9x5dbQhxdgqY KfJTqcifOSNMdGw1UnlkcwPl9lnP7r0u9O/FOSdFVf7S5gyry45AnPcMqPWuBYY1QK9+vZCMPcm nOmJc+v+vd/L3BBAk X-Received: by 2002:a05:600c:91d:b0:3e2:668:3ed7 with SMTP id m29-20020a05600c091d00b003e206683ed7mr3338188wmp.1.1676545305250; Thu, 16 Feb 2023 03:01:45 -0800 (PST) X-Google-Smtp-Source: AK7set+OFHhrzLoDINOIw5SqQtAninJ8ylAaeCFlYtZeD42IvN4cWNCvjf+X25DXWAkpUabrQ87eYw== X-Received: by 2002:a05:600c:91d:b0:3e2:668:3ed7 with SMTP id m29-20020a05600c091d00b003e206683ed7mr3338154wmp.1.1676545304870; Thu, 16 Feb 2023 03:01:44 -0800 (PST) Received: from ?IPV6:2003:cb:c708:bc00:2acb:9e46:1412:686a? (p200300cbc708bc002acb9e461412686a.dip0.t-ipconnect.de. [2003:cb:c708:bc00:2acb:9e46:1412:686a]) by smtp.gmail.com with ESMTPSA id o10-20020a1c750a000000b003dc4aae4739sm4815014wmc.27.2023.02.16.03.01.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Feb 2023 03:01:44 -0800 (PST) Message-ID: Date: Thu, 16 Feb 2023 12:01:43 +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: [PATCH 00/19] mm: Introduce a cgroup to limit the amount of locked and pinned memory To: Alistair Popple , linux-mm@kvack.org, cgroups@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jgg@nvidia.com, jhubbard@nvidia.com, tjmercier@google.com, hannes@cmpxchg.org, surenb@google.com, mkoutny@suse.com, daniel@ffwll.ch, "Daniel P . Berrange" , Alex Williamson 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: rspam02 X-Rspamd-Queue-Id: 4762C4002C X-Stat-Signature: 8cz1g1rsum9ywaipeefsjbcg9m68ew5f X-HE-Tag: 1676545308-437177 X-HE-Meta: U2FsdGVkX1/Ff+dK5C7QtvX9pwx7Qen5UJj1NQ8nOHGBf4omqMIUHXdwD4kU01u6dGQWba15FRHQ7FudnAl8VF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OOpniouUq5uwNU3qSplRYGG0stB5gvTH7R8vFuhML0jzan45srbZ3wyJTHsT1aQQayRJRctBEp8d6tWFC1fidzxcMKldewZAI67xO8ql4CW1qubct8AB7kooSrOvcmPQoIyZdS0K9tCLCTozUPz2NqPqlD3p5Wcz9bHShRvE9bsADoW3mrRuweJ7W+/5nIlpSs0qr6WV5r+LDn2aLwqfh0Ej1NqFZGE3NmEMcNTCGrIHXZcFdcvs1PsoKmWqp49cXMH6bH5N6jLGycPyfVBv1qKad58= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 06.02.23 08:47, 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 controller and converts > core mm code such as mlock over to charging the cgroup before finally > introducing some selftests. > > Rather than adding onto an exisiting cgroup controller such as memcg > we introduce a new controller. This is primarily because we wish to > limit the total number of pages tasks within a cgroup may pin/lock. > > 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. > > Note that this series is based on v6.2-rc5 and > https://lore.kernel.org/linux-rdma/20230201115540.360353-1-bmt@zurich.ibm.com/ > which makes updating the siw driver easier (thanks Bernard). > > Changes from initial RFC: > > - Fixes to some driver error handling. > > - Pages charged with vm_account will always increment mm->pinned_vm > and enforce the limit against user->locked_vm or mm->pinned_vm > depending on initialisation flags. > > - Moved vm_account prototypes and struct definitions into a separate header. > > - Minor updates to commit messages and kernel docs (thanks to Jason, > Christoph, Yosry and T.J.). > > Outstanding issues: > > - David H pointed out that the vm_account naming is potentially > confusing and I agree. However I have yet to come up with something > better so will rename this in a subsequent version of this series > (suggestions welcome). vm_lockaccount ? vm_pinaccount ? Less confusing than reusing VM_ACCOUNT which translates to "commit accounting". Might also make sense to rename VM_ACCOUNT to VM_COMMIT or sth like that. -- Thanks, David / dhildenb