shmget: make small free numbers reusable.

Change-Id: Ic6670214fa31a309e96794361e3ec2dcc6375f4a
Refs: #1531
This commit is contained in:
Tomoki Shirasawa
2020-09-01 07:26:02 +09:00
committed by Masamichi Takagi
parent b3ddd60277
commit e6e66e0392
3 changed files with 42 additions and 26 deletions

View File

@@ -225,8 +225,6 @@ int shmobj_create_indexed(struct shmid_ds *ds, struct shmobj **objp)
static void shmobj_destroy(struct shmobj *obj)
{
extern struct shm_info the_shm_info;
extern struct list_head kds_free_list;
extern int the_maxi;
struct shmlock_user *user;
size_t size;
int npages;
@@ -306,27 +304,13 @@ static void shmobj_destroy(struct shmobj *obj)
kfree(obj);
}
else {
int i = obj->index / 64;
unsigned long x = 1UL << (obj->index % 64);
list_del(&obj->chain);
--the_shm_info.used_ids;
list_add(&obj->chain, &kds_free_list);
/* For index reuse, release in descending order of index. */
for (;;) {
struct shmobj *p;
list_for_each_entry(p, &kds_free_list, chain) {
if (p->index == the_maxi) {
break;
}
}
if (&p->chain == &kds_free_list) {
break;
}
list_del(&p->chain);
kfree(p);
--the_maxi;
}
shmid_index[i] &= ~x;
kfree(obj);
}
return;
}