From: William Lee Irwin III <wli@holomorphy.com>
To: linux-kernel@vger.kernel.org
Subject: [7/11] hugetlb: substitute hugetlb_key for struct inode
Date: Tue, 12 Nov 2002 00:28:53 -0800 [thread overview]
Message-ID: <E18BWPl-0005KI-00@holomorphy> (raw)
This removes many direct usages of struct inode within the key
manipulation API in exchange for passing references to the key
structure itself.
hugetlbpage.c | 78 ++++++++++++++++++++++------------------------------------
1 files changed, 30 insertions(+), 48 deletions(-)
diff -urpN htlb-2.5.47-6/arch/i386/mm/hugetlbpage.c htlb-2.5.47-7/arch/i386/mm/hugetlbpage.c
--- htlb-2.5.47-6/arch/i386/mm/hugetlbpage.c 2002-11-11 21:55:12.000000000 -0800
+++ htlb-2.5.47-7/arch/i386/mm/hugetlbpage.c 2002-11-11 22:21:49.000000000 -0800
@@ -28,57 +28,37 @@ static LIST_HEAD(htlbpage_freelist);
static spinlock_t htlbpage_lock = SPIN_LOCK_UNLOCKED;
#define MAX_ID 32
-static struct htlbpagekey {
+
+struct hugetlb_key {
struct inode *in;
int key;
int busy;
-} htlbpagek[MAX_ID];
+};
-struct hugetlb_key;
+static struct hugetlb_key htlbpagek[MAX_ID];
static void mark_key_busy(struct hugetlb_key *hugetlb_key)
{
- struct inode *inode = (struct inode *)hugetlb_key;
- int i, key = inode->i_ino;
-
- for (i = 0; i < MAX_ID; ++i)
- if (htlbpagek[i].key != key)
- continue;
- BUG_ON(i >= MAX_ID);
- htlbpagek[i].busy = 1;
+ hugetlb_key->busy = 1;
}
static void clear_key_busy(struct hugetlb_key *hugetlb_key)
{
- struct inode *inode = (struct inode *)hugetlb_key;
- int i, key = inode->i_ino;
-
- for (i = 0; i < MAX_ID; ++i)
- if (htlbpagek[i].key != key)
- continue;
- BUG_ON(i >= MAX_ID);
- htlbpagek[i].busy = 0;
+ hugetlb_key->busy = 0;
}
static int key_busy(struct hugetlb_key *hugetlb_key)
{
- struct inode *inode = (struct inode *)hugetlb_key;
- int i, key = inode->i_ino;
-
- for (i = 0; i < MAX_ID; ++i)
- if (htlbpagek[i].key != key)
- continue;
- BUG_ON(i >= MAX_ID);
- return htlbpagek[i].busy;
+ return hugetlb_key->busy;
}
-static struct inode *find_key_inode(int key)
+static struct hugetlb_key *find_key(int key)
{
int i;
for (i = 0; i < MAX_ID; i++) {
if (htlbpagek[i].key == key)
- return (htlbpagek[i].in);
+ return &htlbpagek[i];
}
return NULL;
}
@@ -89,17 +69,18 @@ static int check_size_prot(struct inode
*/
struct hugetlb_key *alloc_key(int key, unsigned long len, int prot, int flag, int *new)
{
- struct inode *inode;
+ struct hugetlb_key *hugetlb_key;
do {
spin_lock(&htlbpage_lock);
- inode = find_key_inode(key);
- if (!inode) {
+ hugetlb_key = find_key(key);
+ if (!hugetlb_key) {
if (!capable(CAP_SYS_ADMIN) || !in_group_p(0))
- inode = ERR_PTR(-EPERM);
+ hugetlb_key = ERR_PTR(-EPERM);
else if (!(flag & IPC_CREAT))
- inode = ERR_PTR(-ENOENT);
+ hugetlb_key = ERR_PTR(-ENOENT);
else {
+ struct inode *inode;
inode = kmalloc(sizeof(struct inode), GFP_ATOMIC);
if (!inode)
inode = ERR_PTR(-ENOMEM);
@@ -110,15 +91,16 @@ struct hugetlb_key *alloc_key(int key, u
break;
if (i == MAX_ID) {
kfree(inode);
- inode = ERR_PTR(-ENOMEM);
+ hugetlb_key = ERR_PTR(-ENOMEM);
} else {
+ hugetlb_key = &htlbpagek[i];
inode_init_once(inode);
- mark_key_busy((struct hugetlb_key *)inode);
+ mark_key_busy(hugetlb_key);
inode->i_mapping = &inode->i_data;
inode->i_mapping->host = inode;
inode->i_ino = (unsigned long)key;
- htlbpagek[i].key = key;
- htlbpagek[i].in = inode;
+ hugetlb_key->key = key;
+ hugetlb_key->in = inode;
inode->i_uid = current->fsuid;
inode->i_gid = current->fsgid;
inode->i_mode = prot;
@@ -127,15 +109,17 @@ struct hugetlb_key *alloc_key(int key, u
}
}
}
- } else if (key_busy((struct hugetlb_key *)inode)) {
- inode = ERR_PTR(-EAGAIN);
+ } else if (key_busy(hugetlb_key)) {
+ hugetlb_key = ERR_PTR(-EAGAIN);
spin_unlock(&htlbpage_lock);
- } else if (check_size_prot(inode, len, prot, flag) < 0)
- inode = ERR_PTR(-EINVAL);
- else
+ } else if (check_size_prot(hugetlb_key->in, len, prot, flag) < 0) {
+ kfree(hugetlb_key->in);
+ hugetlb_key->key = 0;
+ hugetlb_key = ERR_PTR(-EINVAL);
+ } else
*new = 0;
- } while (inode == ERR_PTR(-EAGAIN));
- return (struct hugetlb_key *)inode;
+ } while (hugetlb_key == ERR_PTR(-EAGAIN));
+ return hugetlb_key;
}
static void release_key(struct hugetlb_key *key)
@@ -389,9 +373,7 @@ static int check_size_prot(struct inode
static int prefault_key(struct hugetlb_key *key, struct vm_area_struct *vma)
{
- struct inode *inode = (struct inode *)key;
-
- return hugetlb_prefault(inode->i_mapping, vma);
+ return hugetlb_prefault(key->in->i_mapping, vma);
}
static int alloc_shared_hugetlb_pages(int key, unsigned long addr, unsigned long len, int prot, int flag)
reply other threads:[~2002-11-12 8:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E18BWPl-0005KI-00@holomorphy \
--to=wli@holomorphy.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®