From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935391AbcHBQTl (ORCPT ); Tue, 2 Aug 2016 12:19:41 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:37146 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935246AbcHBQOs (ORCPT ); Tue, 2 Aug 2016 12:14:48 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Nikolay Borisov Cc: jlayton@poochiereds.net, viro@zeniv.linux.org.uk, bfields@fieldses.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, containers@lists.linux-foundation.org, serge.hallyn@canonical.com References: <1470148943-21835-1-git-send-email-kernel@kyup.com> Date: Tue, 02 Aug 2016 11:00:39 -0500 In-Reply-To: <1470148943-21835-1-git-send-email-kernel@kyup.com> (Nikolay Borisov's message of "Tue, 2 Aug 2016 17:42:23 +0300") Message-ID: <87r3a7qhy0.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1bUcKK-0002dU-5L;;;mid=<87r3a7qhy0.fsf@x220.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=67.3.204.119;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX19s3UHBQRUByR183ThC07MPNuch+C8xTDU= X-SA-Exim-Connect-IP: 67.3.204.119 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.7 XMSubLong Long Subject * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Nikolay Borisov X-Spam-Relay-Country: X-Spam-Timing: total 2408 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 3.2 (0.1%), b_tie_ro: 2.3 (0.1%), parse: 1.02 (0.0%), extract_message_metadata: 17 (0.7%), get_uri_detail_list: 2.0 (0.1%), tests_pri_-1000: 4.0 (0.2%), tests_pri_-950: 1.19 (0.0%), tests_pri_-900: 0.99 (0.0%), tests_pri_-400: 20 (0.8%), check_bayes: 19 (0.8%), b_tokenize: 5 (0.2%), b_tok_get_all: 8 (0.3%), b_comp_prob: 1.78 (0.1%), b_tok_touch_all: 2.3 (0.1%), b_finish: 0.69 (0.0%), tests_pri_0: 2354 (97.8%), check_dkim_signature: 0.45 (0.0%), check_dkim_adsp: 2164 (89.9%), tests_pri_500: 3.5 (0.1%), rewrite_mail: 0.00 (0.0%) Subject: Re: [RFC PATCH] locks: Show only file_locks created in the same pidns as current process X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Nikolay Borisov writes: > Currently when /proc/locks is read it will show all the file locks > which are currently created on the machine. On containers, hosted > on busy servers this means that doing lsof can be very slow. I > observed up to 5 seconds stalls reading 50k locks, while the container > itself had only a small number of relevant entries. Fix it by > filtering the locks listed by the pidns of the current process > and the process which created the lock. The locks always confuse me so I am not 100% connecting locks to a pid namespace is appropriate. That said if you are going to filter by pid namespace please use the pid namespace of proc, not the pid namespace of the process reading the file. Different contents of files depending on who opens them is generally to be discouraged. Eric > Signed-off-by: Nikolay Borisov > --- > fs/locks.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/fs/locks.c b/fs/locks.c > index 6333263b7bc8..53e96df4c583 100644 > --- a/fs/locks.c > +++ b/fs/locks.c > @@ -2615,9 +2615,17 @@ static int locks_show(struct seq_file *f, void *v) > { > struct locks_iterator *iter = f->private; > struct file_lock *fl, *bfl; > + struct pid_namespace *pid_ns = task_active_pid_ns(current); > + > > fl = hlist_entry(v, struct file_lock, fl_link); > > + pr_info ("Current pid_ns: %p init_pid_ns: %p, fl->fl_nspid: %p nspidof:%p\n", pid_ns, &init_pid_ns, > + fl->fl_nspid, ns_of_pid(fl->fl_nspid)); > + if ((pid_ns != &init_pid_ns) && fl->fl_nspid && > + (pid_ns != ns_of_pid(fl->fl_nspid))) > + return 0; > + > lock_get_status(f, fl, iter->li_pos, ""); > > list_for_each_entry(bfl, &fl->fl_block, fl_block)